GetSchoolsQueryHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 28
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A execute 0 24 2
1
import { QueryHandler } from '@nestjs/cqrs';
2
import { Inject } from '@nestjs/common';
3
import { GetSchoolsQuery } from './GetSchoolsQuery';
4
import { Pagination } from 'src/Application/Common/Pagination';
5
import { ISchoolRepository } from 'src/Domain/School/Repository/ISchoolRepository';
6
import { SchoolView } from '../View/SchoolView';
7
8
@QueryHandler(GetSchoolsQuery)
9
export class GetSchoolsQueryHandler {
10
  constructor(
11
    @Inject('ISchoolRepository')
12
    private readonly schoolRepository: ISchoolRepository
13
  ) {}
14
15
  public async execute(
16
    query: GetSchoolsQuery
17
  ): Promise<Pagination<SchoolView>> {
18
    const { page } = query;
19
    const schoolViews: SchoolView[] = [];
20
    const [ schools, total ] = await this.schoolRepository.findSchools(page);
21
22
    for (const school of schools) {
23
      schoolViews.push(
24
        new SchoolView(
25
          school.getId(),
26
          school.getName(),
27
          school.getReference(),
28
          school.getAddress(),
29
          school.getCity(),
30
          school.getZipCode(),
31
          school.getStatus(),
32
          school.getType()
33
        )
34
      );
35
    }
36
37
    return new Pagination<SchoolView>(schoolViews, total);
38
  }
39
}
40